package com.mass.core.sys.authority.services.impl;

import java.util.List;

import com.mass.core.sys.authority.model.SysAuthority;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;

import com.mass.core.sys.authority.dao.SysAuthorityMapper;
import com.mass.core.sys.authority.services.SysAuthorityServices;
import com.mass.core.sys.menu.model.SysMenu;
import com.mass.core.sys.metadata.model.SysMetadata;
import com.mass.core.sys.role.services.SysRoleServices;
import com.mass.core.sys.user.model.SysUser;
import com.mass.core.sys.user.services.SysUserServices;
@Service
public class SysAuthorityServicesImpl implements SysAuthorityServices {

	@Autowired
	private SysUserServices sysUserServices;   //注入用户接口
	@Autowired
	private SysAuthorityMapper sysAuthorityMapper; //注入权限dao接口
	
	@Autowired
	private SysRoleServices roleServices;	   //注入角色接口
	

	/**
	 * 
	* @Title: querySysMenuTemp
	* @Description: 查询用户权限  
	* @param sysUser 登录用户
	* @return  List<SysMenuTemp> 返回类型   
	* @throws
	 */
	
	@Transactional
	public List<SysMenu> querySysMenu(SysUser sysUser) {
		if(!ObjectUtils.isEmpty(sysUser))
			return sysAuthorityMapper.querySysMenu(sysUser.getId(), sysUser.getRoleId(), (long)0);
		else
			return null;
	}

	
	public int insertSysAuthority(SysAuthority sysAuthority) {
		return sysAuthorityMapper.insertSelective(sysAuthority);
	}

	
	public List<SysMetadata> querySysMetadataByMenuId(Long userId, Long menuId) {
		List<SysMetadata> sysMetadatas = sysAuthorityMapper.querySysMetadataByMenuId(menuId, 0, userId);
		if(sysMetadatas.size()>0){
			return sysMetadatas;
		}else{
			return null;
		}
	}


	
	public List<SysMenu> querySysMenuByMenuId(Long userId, Long menuId) {
		List<SysMenu> sysMenus =  sysAuthorityMapper.querySysMenuByMenuId(userId, menuId);
		if(sysMenus.size()>0){
			return sysMenus;
		}else{
			return null;
		}
	}
}
